import { mapGetters } from 'vuex'

export default {
	data() {
		return {
			startTime: null,
		}
	},
	computed: {
	  ...mapGetters('global', ['getDeviceInfo']),
	  ...mapGetters('user', ['getUserInfo']),
		// 返回上报时间，单位：秒
		diffTime(){
			return () => {
				const now = new Date().getTime()
				return Math.round((now - this.startTime) / 1000)
			}
		}
	},
	methods: {
		// 设置实际开始时间
		setStartTime(time){
			if(time){
				this.startTime = time
			}else {
				this.startTime = new Date().getTime()
			}
		},
		// 自主上报
		async autoReport(data){
			const res = await this.$request({
			  url: '/report-center/app-event/report',
			  data: {
					...this.getDeviceInfo,
					...data,
					userId: this.getUserInfo.id
				}
			}).catch(res => {
				console.log('自主上报失败', res);
			})
		}
	}
}